package com.the4man.framework.util.dialect;

/**
 * Created by lenovo on 2017/12/12.
 */
public class MysqlDialect extends Dialect {
    public MysqlDialect() {
    }

    public String getLimitString(String sql, int offset, int limit) {
        sql = sql.trim();
        StringBuffer pagingSelect = new StringBuffer(sql.length() + 100);
        pagingSelect.append("select r.* from ( ");
        pagingSelect.append(sql);
        pagingSelect.append(") r ");
        pagingSelect.append("limit ").append(" ").append(offset).append(",").append(limit);
        return pagingSelect.toString();
    }

    public String getOrderByString(String sql, String sortfiled, String orderby) {
        sql = sql.trim();
        StringBuilder orderSelect = (new StringBuilder(sql.length() + 200)).append("select r.* from ( ").append(sql).append(" ) r ").append(" order by ").append(sortfiled).append(" ").append(orderby);
        return orderSelect.toString();
    }
}
